<?php /*
	EZ-Shop, Starter E-Commerce Platform
    Copyright (C) 2009  David Hinchliffe - FC Software Ltd

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/ ?>
<?php
function fcflush()
{
	static $output_handler = null;
	if ($output_handler === null)
	{
		$output_handler = @ini_get('output_handler');
	}

	if ($output_handler == 'ob_gzhandler')
	{
		// forcing a flush with this is very bad
		return;
	}

	flush();
	if (function_exists('ob_flush') AND function_exists('ob_get_length') AND ob_get_length() !== false)
	{
		@ob_flush();
	}
	else if (function_exists('ob_end_flush') AND function_exists('ob_start') AND function_exists('ob_get_length') AND ob_get_length() !== FALSE)
	{
		@ob_end_flush();
		@ob_start();
	}
}
################################################################
#		Common Function
##################################################################

// FUNCTION FOR THE SENDING SIMPLE OR HTML MAILS
function SendEmail($to,$from,$subject,$msg,$cond)
{
	//$cond=0     For the simple mail to send
	//$cond=1     For Html Format Mail Send
	if($cond==0)
	{
    	$mail_subject = $subject;
		$message = $msg;
		$mail_to = $to;
		$mail_from = $from;
    	$headers = "From:".$mail_from;

		mail($mail_to, $mail_subject, $message, $headers);
	}
	if($cond==1)
	{
		/* recipients */
		//-->$to  = "mary@example.com" . ", " ; // note the comma


		/* subject */
		//-->$subject = "Birthday Reminders for August";

		/* message */
				$message = '
					<html>
					<head>
					<title>'.$_SESSION['config_val'][0]['varcurrency'].'</title>
					</head>
					<body>
					<table width=100% border=0 cellspacing=0 cellpadding=0 >
					 <tr>
    					<td class="skinbg">'.$msg.'</td>
  					</tr>
					<tr>
    					<td class="skinbg">&nbsp;</td>
  					</tr>
					</table>
					</body>
					</html>';

			/* To send HTML mail, you can set the Content-type header. */
			$headers  = "MIME-Version: 1.0\r\n";
			$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

			/* additional headers */
			$headers .= "To: ".$to."\r\n";
			$headers .= "From: ".$from."\r\n";
						
			/* and now mail it */
			mail($to, $subject, $message, $headers);
	
	}
}


// FUNCTION FOR CHECKING THE VARAIBLE IS SET OR NOT (REQUEST  OR SESSION )
function issetvar($val="",$fixkept="")
{
	
	if(isset($_REQUEST[$val]))
	{
		return $_REQUEST[$val];
	}
	else
	{
		if(isset($_SESSION[$val]))
		{
			return $_SESSION[$val];
		}
		else
		{	
			if(trim($fixkept)!="")
			{
				return $fixkept;
			}
			else
			{
				return false;
			}
		}
	}
}


// FUNCTION FOR CHECKING  THAT ANY MAGIC QUOTES ARE REPLACED IN STRING
function mymagictxt($theValue)
{
	$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;	
	$theValue= str_replace("%<%","&lt;",$theValue);
	$theValue= str_replace("%>%","&gt;",$theValue);
	return $theValue;
}

//FUNCTION FOR CHECKING THAT THE ADMIN LOGIN AS BEEN MADE OR NOT
function loginadmincheck()
{
	
	if(isset($_SESSION["loginvalidate"]) && $_SESSION["loginvalidate"]!="" 
	&& $_SESSION["loginvalidate"]=="valid" )
	{
		return true;
	}
	else
	{
		return false;
	}

}

//function for the display the member name
function memname()
{
	if(isset($_SESSION['membername']) && $_SESSION['membername']!="")
				{
					$url="<a href='memberdet.php?fid=".$_SESSION['memberid']."' class='heading'>".$_SESSION['membername']."</a>";
					echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='heading'>
					Welcome ".$url."</span>";
					//$_SESSION['memberid']
				}
}

// FUNCTION FOR CHECKING ACTIONS OF FORM
function actionfrmcheck($var="",$val="")
{
	//echo $_REQUEST[$var]."$var-->$val";
	if( isset($_REQUEST[$var])  && ($_REQUEST[$var]!="") &&  ($_REQUEST[$var]==$val) )
	{
		return true;
	}
	else
	{
		return false;
	}
}

// FUNCTION FOR CHECKING ACTIONS OF FORM
function actionfrmcheckrm($var="")
{
	//echo $_REQUEST[$var]."$var-->$val";
	if( isset($_REQUEST[$var])  && ($_REQUEST[$var]!="") )
	{
		return true;
	}
	else
	{
		return false;
	}
}

// FUNCTION FOR THE FETCHING THE VALUE FROM CONFIG AND STORE IN SESSION
function configvalfetch($obj_db)
{
	$sql="SELECT * FROM `tblimagesettings`";
					//echo $sql;
					$_SESSION['config_val']=$obj_db->select($sql);
					//print_r($res_settting);
	if($_SESSION['config_val'])
	{
		
		//$_SESSION['config_val']=$res_settting;
	}
	else
	{
		header("location:thankyou.php?msg=cnfgfet");
		die();
	}				

}

//FUNCTION FOR THE PER PAGE ROW DISPLAY DROP DOWN CREATE
function drpdown_display($maxval)
{
	echo " <select name='sltpage' onChange='this.form.submit();'>";
	//echo "<option value=0>Select</option>";
	if(actionfrmcheckrm('sltpage') )
	{
			$tmppage=$_REQUEST['sltpage'];								
	}
	for($i=0;$i<$maxval;$i=$i+ DRPPG )
	{
		$slted="";
		if($tmppage==$i)
		{
			$slted=" Selected";
		}
		
		if($i==0)
		{
			echo "<option value=".$i." $slted >".All."</option>";
		}
		else
		{
			echo "<option value=".$i." $slted >".$i."</option>";
		}
	}
	echo "</select>";
}


//Function for the change the details shown under the serach 
function srchwordchangestyl($words)
{
	if(actionfrmcheckrm('search'))
	{
		$findwrd=$_REQUEST['search'];
		$rplwrd="<span class='srchdisplay'>".$_REQUEST['search']."</span>";
		$words=str_replace("$findwrd",$rplwrd, $words);
		return $words;
	}
	else
	{
		return $words;
	}							
}


//FUNCTION FOR THE CREATING THE IMAGE ACCORDING TO USER SIZE
function createThumb( $sourcepath , $targetpath ,$name , $size )
 {
 		$img = $sourcepath ;
		$handle = fopen ($img, "rb");
		$org = fread ($handle, filesize ($img));
		fclose ($handle);
		$tnsize =$size;
		$img = imagecreatefromstring( $org );
		$w = imagesx( $img );
		$h = imagesy( $img );
		if( $w > $h )
		{
			$ratio = $w / $h;
			$nw = $tnsize;
			$nh = $nw / $ratio;
		} else {
			$ratio = $h / $w;
			$nh = $tnsize;
			$nw = $nh /$ratio;
		}
		$img2 = imagecreatetruecolor( $nw, $nh );
		imagecopyresampled ( $img2, $img, 0, 0, 0 , 0, $nw, $nh, $w, $h );
		$fimg = $name.'.'.'jpg';
		$real_tpath = realpath ($targetpath);
		$file = $real_tpath . "/" . $fimg;
		imagejpeg( $img2, $file );
		return $file;
}

// parsedate from time stamp in linux

function printdate($timestamp)
{
	if(strpos($timestamp, "-"))
	{
		//echo $timestamp;
		$timestamp=explode(" ",$timestamp);
		$timestamp1=explode("-",$timestamp[0]);
		$timestamp2=explode(" ",$timestamp[1]);		
		$yr=$timestamp1[0];
		$month=$timestamp1[1];
		$day=$timestamp1[2];

		$hr=$timestamp[1];
	
	}
	else
	{
		$yr=substr($timestamp, 0, 4);
		$month=substr($timestamp, 4, 2);
		$day=substr($timestamp, 6, 2);
		$hr=substr($timestamp, 8, 8);
		
	}
	$mon[1]="Jan";
	$mon[2]="Feb";
	$mon[3]="Mar";
	$mon[4]="Apr";
	$mon[5]="May";
	$mon[6]="June";
	$mon[7]="July";
	$mon[8]="Aug";
	$mon[9]="Sep";
	$mon[10]="Oct";
	$mon[11]="Nov";
	$mon[12]="Dec";
	
	//$date = $yr."-".$mon[ceil($month)]."-".$day;
	$date = $day."-".$month."-".$yr."(".$hr.")";
	return $date;
	
}

// parsedate from time stamp in linux

function printdate1($timestamp)
{
	if(strpos($timestamp, "-"))
	{
		//echo $timestamp;
		$timestamp=explode(" ",$timestamp);
		$timestamp1=explode("-",$timestamp[0]);
		//$timestamp2=explode(" ",$timestamp[1]);		
		$yr=$timestamp1[0];
		$month=$timestamp1[1];
		$day=$timestamp1[2];

		//$hr=$timestamp[1];
	
	}
	else
	{
		$yr=substr($timestamp, 0, 4);
		$month=substr($timestamp, 4, 2);
		$day=substr($timestamp, 6, 2);
		//$hr=substr($timestamp, 8, 8);
		
	}
	$mon[1]="Jan";
	$mon[2]="Feb";
	$mon[3]="Mar";
	$mon[4]="Apr";
	$mon[5]="May";
	$mon[6]="June";
	$mon[7]="July";
	$mon[8]="Aug";
	$mon[9]="Sep";
	$mon[10]="Oct";
	$mon[11]="Nov";
	$mon[12]="Dec";
	
	//$date = $yr."-".$mon[ceil($month)]."-".$day;
	$date = $day."-".$mon[ceil($month)]."-".$yr;
	return $date;
	
}

//FUNCTION FOR THE CRYPT THE GIVEN PASSWORD INTO CRYPT PASSWORD WITH SERVER NAME
function cyptmypass($pass)
{
	/*$servername=$_SERVER['HTTP_HOST'];
	$pass=crypt($pass,$servername);*/
	return $pass;
}

//Function for the call the function file
function functionfilename()
{
	$func_file=explode("/",$_SERVER['PHP_SELF']);
	$tmpnameid= (count($func_file)-1);
	return $func_file[$tmpnameid];
}

//Function for calling the language file
function languagefilename()
{
	$func_file=explode("/",$_SERVER['PHP_SELF']);
	$tmpnameid= (count($func_file)-1);
	$filelangfld="";
	if($_SESSION['config_val'][0]['intllang']=="1")
	{
		$filelangfld=ENG;
	}
	elseif($_SESSION['config_val'][0]['intllang']=="2")
	{
		$filelangfld=SPNH;
	}
	return LANG.$filelangfld.$func_file[$tmpnameid];
}

//function for include the common trslate file
function languagefilecommon()
{
	$filelangfld="";
	if($_SESSION['config_val'][0]['intllang']=="1")
	{
		$filelangfld=ENG;
	}
	elseif($_SESSION['config_val'][0]['intllang']=="2")
	{
		$filelangfld=SPNH;
	}
	return LANG.$filelangfld."commontrl.php";
}


// Function made for approved and disapprove disp-lay with link on the site
function forapprandundis($val="",$querystr="",$msguser="")
{
	
	if($val=="1")
	{
		if(trim($msguser)=="")
		{
			$msguser="Do you want to Unapprove";
		}
		echo "<a href=".$querystr." onclick='return confirm(".$msguser.");' class='my' >
		<img src='images/unapprove.gif' width='15' height='15' border='0' />&nbsp;Un-Approve</a>";
	}
	else
	{
		if(trim($msguser)=="")
		{
			$msguser="Do you want to Approve";
		}
		
		echo "<a href=".$querystr." onclick='return confirm(".$msguser.");' class='my' >
		<img src='images/approve.gif' width='15' height='15' border='0' />&nbsp;Approve</a>";
		
	}
}


// Function for the file which is that to find and accroding to that action
function pageindcatesign($filenamecomp="",$cond="")
{
$func_file=explode("/",$_SERVER['PHP_SELF']);
$tmpnameid= (count($func_file)-1);
$filenametmp=$func_file[$tmpnameid];
$filenametmp=explode("?",$filenametmp);
$filenametmp=$filenametmp[0];
if($filenametmp=='templete.php')
{
	if($cond=="0")
	{
		echo "<img src='images/mainpage.jpg' height='100' />";	
	}
	else
	{
	
	}

}
else if($filenametmp=='about.php')
{
	if($cond=="0")
	{
		echo "<img src='images/aboutme.jpg' height='100' />";	
	}
	else
	{
	
	}

}

else if($filenametmp=='training.php')
{
	if($cond=="0")
	{
		echo "<img src='images/training.jpg' height='100' />";	
	}
	else
	{
	
	}

}
else if($filenametmp=='clients.php')
{
	if($cond=="0")
	{
		echo "<img src='images/client.jpg' height='100' />";	
	}
	else
	{
	
	}

}
else if($filenametmp=='contact.php')
{
	if($cond=="0")
	{
		echo "<img src='images/contact.jpg' height='100' />";	
	}
	else
	{
	
	}

}
else if($filenametmp=='gallery.php')
{
	if($cond=="0")
	{
		echo "<img src='images/gallery.jpg' height='100' />";	
	}
	else
	{
	
	}

}

}
function imageResize($width, $height, $target, $op) { 
	
		//takes the larger size of the width and height and applies the  
		//formula accordingly...this is so this script will work  
		//dynamically with any size image 
		$check = 0;
		if ($width <= $target && $height <= $target)
		{
			$check = 1;
		}
		if ($check == 0)
		{
			if ($width > $height)
			{ 
				$percentage = ($target / $width); 
			}
			else
			{ 
				$percentage = ($target / $height); 
			}
			//gets the new value and applies the percentage, then rounds the value 
			$width = round($width * $percentage); 
			$height = round($height * $percentage); 
		}
		//returns the new sizes in html image tag format...this is so you 
		//can plug this function inside an image tag and just get the 
		if ($op == "0")
		{
			return $width; 
		}
		elseif ($op == "1")
		{
			return $height; 
		}
	} 

function Getcatiddel($ParentID,$num,$selected,$obj_db,$check)
{
	$value = $ParentID;
	$c="";
				
	$query_RsC = "SELECT * FROM tblcategory WHERE intparentid = ".$ParentID."  ORDER BY varcategory ASC";
	$RsC = $obj_db->select($query_RsC);
	$cnt = count($RsC);
		
	if($RsC)
	{
		for($i=0;$i<$cnt;$i++)
		{	
			$value=$value.",".Getcatiddel($RsC[$i]['intid'],$num+1,$selected,$obj_db,$check);		
		}
	 }
	return $value;
}

function GetChild($ParentID,$num,$selected,$obj_db,$check)
{
		$value = "";
		$c="";
		
		for($i=0;$i<$num;$i++)
		{
			$c=$c."&nbsp;&nbsp;-&nbsp;&nbsp;";
		}
		
		$query_RsC="SELECT tblprodcategory.intcategoryid,tblprodcategory.intparentid, 	
					tblprodcategorydesc.varcategoryname
					FROM tblprodcategory, tblprodcategorydesc
					WHERE tblprodcategory.intcategoryid = tblprodcategorydesc.intcatid AND 	
					intparentid = ".$ParentID;
		//$query_RsC = "SELECT * FROM tblprodcategory WHERE intparentid = ".$ParentID;
		$RsC = $obj_db->select($query_RsC);
		$cnt = count($RsC);
		
		if($RsC)
		{
			for($i=0;$i<$cnt;$i++)
			{
				if($check==1)
				{
						if($selected==$RsC[$i]['intcategoryid'])
						{
						$value=$value."<option value='".$RsC[$i]['intcategoryid']."'selected>".$c.$RsC[$i]['varcategoryname']."</option>";		
						}
						else
						{
						$value=$value."<option value='".$RsC[$i]['intcategoryid']."'>".$c.$RsC[$i]['varcategoryname']."</option>";		
						}
				}
				if($check==2)
				{
					$value=$value.",".$RsC[$i]['intcategoryid'];		
				}
				$value=$value."".GetChild($RsC[$i]['intcategoryid'],$num+1,$selected,$obj_db,$check);
			 }
		 }
	return $value;
}

?>
